package database.helpers;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Seeker_Table {

public databas_helper dbHelper;	
public SQLiteDatabase database;
	/**
	 * Assignment table related constants.
	 */
	public final static String SEEKER_TABLE="Seekeer";	
	public final static String SEEKER_NAME="name";
	public final static String SEEKER_USERNAME="Username";	
	public final static String SEEKER_PIN="pin";
	public final static String SEEKER_ISCHRISTIAN="ISCHRISTIAN";
	public final static String SEEKER_EMAIL="email";	
	public final static String SEEKER_HAVECF="HAVECF";
	public final static String SEEKER_ID="_id";
	
	public Seeker_Table(Context context){
		dbHelper = new databas_helper(context);
		database = dbHelper.getWritableDatabase();
	}
	public Seeker_Table(databas_helper dbHelper,SQLiteDatabase database){
		this.dbHelper = dbHelper;
		this.database = database;
	}
	
	/**\
	 * Creates a new Seeker
	 	 */
	public long addSeeker(String name,String username, String pin, String ISCHRISTIAN, String email, String haveCF){
		ContentValues values = new ContentValues();
		values.put(SEEKER_NAME,name);
		values.put(SEEKER_USERNAME,username);
		values.put(SEEKER_PIN,pin);
		values.put(SEEKER_ISCHRISTIAN,ISCHRISTIAN);
		values.put(SEEKER_EMAIL,email);	
		values.put(SEEKER_HAVECF,haveCF);

		return database.insert(SEEKER_TABLE, null, values);
	}	
	
	public void close() {
		dbHelper.close();
	}
	/**
	 * Fetch all Seekers
	 * @return
	 */
	public Cursor getAllSeekers(){
		Cursor mCursor = database.query(true, SEEKER_TABLE, new String[]
				{
				SEEKER_ID,SEEKER_NAME,SEEKER_USERNAME, SEEKER_PIN, SEEKER_ISCHRISTIAN,SEEKER_EMAIL,SEEKER_HAVECF},null
				, null, null, null, null, null);
		if (mCursor != null) {
			mCursor.moveToFirst();
		}
		return mCursor;
	}
	/**
	 * 
	 */
	public int editSeeker(String name,String username, String pin, String ISCHRISTIAN, String email, String haveCF){
		ContentValues values = new ContentValues();
		values.put(SEEKER_NAME,name);
		values.put(SEEKER_USERNAME,username);
		values.put(SEEKER_PIN,pin);
		values.put(SEEKER_ISCHRISTIAN,ISCHRISTIAN);
		values.put(SEEKER_EMAIL,email);
		values.put(SEEKER_HAVECF,haveCF);
		
		return database.update(SEEKER_TABLE, values,SEEKER_ID + "=?",new String[]{name});
	}
	
	public boolean delete(String name){
		return database.delete(SEEKER_TABLE, SEEKER_ID + "=" + name, null) > 0;
	}
}
